package com.xie.smfs.filter;

import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.registry.Registries;
import net.minecraft.util.Identifier;

import java.util.Arrays;
import java.util.List;

/**
 * 物品过滤器，用于检查物品是否允许放入制图台
 */
public class ItemFilter {
    // 允许的物品ID列表
    private static final List<String> ALLOWED_ITEM_IDS = Arrays.asList(
            "grass_block", "dirt", "stone", "wooden_", "stone_", "iron_", "golden_", "diamond_", "netherite_",
            "shovel", "pickaxe", "axe", "hoe", "sword", "helmet", "chestplate", "leggings", "boots"
    );

    // 允许的特殊物品
    private static final List<Item> ALLOWED_SPECIAL_ITEMS = Arrays.asList(
            Items.GRASS_BLOCK,
            Items.DIRT,
            Items.STONE
            // 可以添加更多允许的基础方块
    );

    /**
     * 检查物品是否是工具
     */
    public static boolean isTool(ItemStack stack) {
        if (stack.isEmpty()) return false;

        Identifier itemId = Registries.ITEM.getId(stack.getItem());
        String itemName = itemId.getPath().toLowerCase();

        // 检查工具和装备
        for (String tool : Arrays.asList("shovel", "pickaxe", "axe", "hoe", "sword",
                "helmet", "chestplate", "leggings", "boots")) {
            if (itemName.contains(tool)) {
                return true;
            }
        }

        return false;
    }

    /**
     * 检查物品是否允许放入制图台
     */
    public static boolean isItemAllowed(ItemStack stack) {
        if (stack.isEmpty()) return true;

        // 检查特殊物品
        if (ALLOWED_SPECIAL_ITEMS.contains(stack.getItem())) {
            return true;
        }

        // 检查工具和装备
        String itemId = stack.getItem().toString().toLowerCase();
        for (String allowed : ALLOWED_ITEM_IDS) {
            if (itemId.contains(allowed)) {
                return true;
            }
        }

        return false;
    }

    /**
     * 获取允许的物品描述（用于提示）
     */
    public static String getAllowedItemsDescription() {
        return "草方块、工具和装备";
    }
}